package com.xl98.service.impl;

import com.xl98.entity.Appointment;
import com.xl98.entity.State;
import com.xl98.mapper.AppointmentMapper;
import com.xl98.mapper.StateMapper;
import com.xl98.mapper.UserMapper;
import com.xl98.service.StateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2020-05-15
 */
@Service
public class StateServiceImpl extends ServiceImpl<StateMapper, State> implements StateService {
    @Autowired
    private StateMapper stateMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private AppointmentMapper appointmentMapper;

    @Override
    public List<State> findAllState() {
        return stateMapper.selectList(null);
    }

    @Override
    public boolean insert(State state) {
        if(stateMapper.insert(state)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(State state) {
        if(stateMapper.updateById(state)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(String id) {
        if(stateMapper.deleteById(id)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateUserState(String userId, String stateId) {
        System.out.println(stateId);
        Map<String, String> map = new HashMap<>();
        map.put("id",userId);
        map.put("stateId",stateId);
        if(userMapper.updateUserState(map)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateAppointmentState(String appointmentId, String stateId) {
        Appointment appointment = appointmentMapper.selectById(appointmentId);
        appointment.setStateId(stateId);
        if(appointmentMapper.updateById(appointment)>0){
            return true;
        }
        return false;
    }
}
